import api from '@/utils/api'
import type { 
  ApiResponse, 
  User, 
  LoginRequest, 
  RegisterRequest 
} from '@/types/api'

export class AuthService {
  /**
   * 用户登录
   */
  static async login(data: LoginRequest): Promise<ApiResponse<{
    access_token: string
    refresh_token: string
    user: User
  }>> {
    const response = await api.post('/auth/login/', data)
    return response.data
  }

  /**
   * 用户注册
   */
  static async register(data: RegisterRequest): Promise<ApiResponse> {
    const response = await api.post('/auth/register/', data)
    return response.data
  }

  /**
   * 用户登出
   */
  static async logout(refreshToken: string): Promise<ApiResponse> {
    const response = await api.post('/auth/logout/', {
      refresh_token: refreshToken
    })
    return response.data
  }

  /**
   * 获取用户信息
   */
  static async getUserInfo(): Promise<ApiResponse<User>> {
    const response = await api.get('/auth/user-info/')
    return response.data
  }

  /**
   * 刷新Token
   */
  static async refreshToken(refreshToken: string): Promise<ApiResponse<{
    access_token: string
    refresh_token: string
  }>> {
    const response = await api.post('/auth/refresh/', {
      refresh: refreshToken
    })
    return response.data
  }

  /**
   * 修改密码
   */
  static async changePassword(data: {
    old_password: string
    new_password: string
    confirm_password: string
  }): Promise<ApiResponse> {
    const response = await api.post('/auth/change-password/', data)
    return response.data
  }

  /**
   * 重置密码
   */
  static async resetPassword(email: string): Promise<ApiResponse> {
    const response = await api.post('/auth/reset-password/', { email })
    return response.data
  }
}
